package server

import (
	"fmt"
	"github.com/garyburd/redigo/redis"
)

const (
	VarKeyName             = "CARDS_VAR"
	GameHouseLastNo        = "gamehouse_last_no"
	GameHouseLastNoIncSpan = 3
)

func GenerateGameID() (string, error) {
	conn := RedisPool.Get()
	lastNo, err := redis.Int(conn.Do("HINCRBY", VarKeyName, GameHouseLastNo, GameHouseLastNoIncSpan))
	if err != nil {
		return "", err
	}
	return fmt.Sprintf("%d", lastNo), nil
}

func GetUsersClubsByUidAndClubId(uid, clubId string) (*CurrentClub, error) {
	var uc CurrentClub
	exist, err := DBEngine.Where("uid=?", uid).And("club_id=?", clubId).Get(&uc)
	if err != nil {
		return nil, err
	}
	if !exist {
		return nil, nil
	}
	return &uc, nil
}
